<template>

    <div class="login-container">
        <div class="login-container full-screen-background">

            <div class="bigbox">
                <div class="list">
                    <div class="login"  style="font-size: 33px;">
                        <p class="tab-link" active-class="active" style="font-size: 33px;">Login</p>
                    </div>
                    <input type="text" v-model="credentials.username" placeholder="e-mail/phone/Username" />
                    <input type="password" v-model="credentials.password" placeholder="password" />
                    <div class="login-options">
                        <label style="font-size: 15px;">
                            <input type="checkbox" v-model="autoLogin"  /> Automatic login
                        </label>
                        <router-link to="/password" @click.prevent  style="font-size: 15px;">miss your password?</router-link>
                    </div>
                    <Router-link to="/">
                        <button @click="login">Sign up</button>
                    </Router-link>

                </div>



                <div class="separator">
                    <div class="line-vertical">
                        <p>No account number ? :
                            <router-link to="/register">Sign In</router-link>
                        </p>
                    </div>
                </div>
                <!-- 模态框结构 -->
                <div v-if="isModalVisible" class="modal">
                    <div class="modal-content">
                        <span class="close" @click="hideModal">&times;</span>
                        <p>{{ privacyPolicyContent }}</p>
                    </div>
                </div>
            </div>

        </div>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import axios from 'axios';
import { useRouter } from 'vue-router';

const credentials = ref({
    username: '22000901',
    password: '1234',
});

const router = useRouter();
const autoLogin = ref(false);


// 登录方法
const login = async () => {
    try {
        // 使用axios发送登录请求
        const response = await axios.post('/api/login', credentials.value, {
            headers: {
                'Authorization': 'Bearer ' + localStorage.getItem('token') // 如果有token，可以添加到请求头中
            }
        });
        // 假设服务器响应的格式是 { success: true/false, message: '描述信息', data: { /* 一些数据 */ } }
        if (response.data.success) {
            // 登录成功，可能需要保存一些信息，如token
            localStorage.setItem('token', response.data.token);
            // 登录成功，跳转到目标页面
            router.push('/'); // 假设目标路由的路径为 '/home'
        } else {
            // 登录失败，提示用户
            alert(response.data.message);
        }
    } catch (error) {
        console.error('Login:', error);
        alert('Landing successful !!!');
    }
};



// 控制模态框显示的状态
const isModalVisible = ref(false);


// 显示模态框
const showModal = () => {
    isModalVisible.value = true;
};

// 隐藏模态框
const hideModal = () => {
    isModalVisible.value = false;
};
</script>

<style scoped>
body,
.full-screen-background {
    /* 使用CSS的url函数引用本地图片 */
    background-image: url('../assets/bg.jpg');
    background-size: cover;
    background-position: center center;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
}
.login-container::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url('../assets/bg.jpg');
    background-size: cover;
    background-position: center center;
    z-index: -1;
}

html {
    margin: 0;
    padding: 0;
    height: 100%;
}

.bigbox {
    border: 2px solid #cfcfcfba;
    border-radius: 10px;
    background-clip: padding-box;
    /* 确保背景不延伸到边框下面 */
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.1);
    /* 确保有足够的空间显示阴影 */
    padding: 30px;
    padding-bottom: -10px;
    background-color: rgba(234, 234, 234, 0.197);
    /* 可以设置一个边界半径，让边框看起来更平滑 */
    border-radius: 35px;
}


.list {
    margin-top: 125px;
}

.logo-and-text {
    display: flex;
    align-items: center;
    /* 垂直居中 */
    justify-content: flex-start;
    /* 水平方向从左侧开始 */
    margin-bottom: 20px;
    /* 根据需要调整 */
    text-align: left;
    /* 确保文本也是左对齐的（尽管这是默认行为） */
}




.login-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 0px;
    box-sizing: border-box;
    min-width: 100%;
}

.login .tab-link {
    color: #425c78;
    margin: 0 0px;
    text-decoration: none;
    font-size: 29px;
    font-weight: bold
}

.login .tab-link.active {
    color: #0b3570bd;
    text-decoration: underline;
}

.login {
    margin: 95px;
    text-align: center;
}

.login-options {
    display: flex;
    justify-content: space-between;
    margin-bottom: 58px;
    align-items: center;
}

.login-options label {
    display: flex;
    align-items: center;
    margin-right: 10px;
    white-space: nowrap;
}

.login-options a {
    color: #007bff;
    text-decoration: none;
    flex-grow: 1;
    margin-left: auto;
    text-align: right;
}


.login-options input[type="checkbox"] {
    margin: 15px;
    align-items: center;
}

.login-options a:hover {
    text-decoration: underline;
}

button {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 20px;
    background-color: #4c88cc;
    color: white;
    font-size: 16px;
    cursor: pointer;
}

button:hover {
    background-color: #0056b3;
}



.list {
    margin-bottom: 8vw;

}

input {
    width: 100%;
    padding: 12px;
    margin-bottom: 20px;
    border: 3px solid #bbbaba;
    border-radius: 20px;
    box-sizing: border-box;
    background-color: rgb(242, 238, 238);
}




a {
    color: #007bff;
    text-decoration: none;
}



.separator {
    margin-top: 2vw;
    display: flex;
    flex-direction: column;
    justify-content: center;
    flex: 1;
    margin-top: 10em;
}



.line-vertical p {
    margin-top: -1vh;
    text-align: center;
}

.privacy-policy p {
    margin-top: 15px;
    text-align: center;
}

.line-vertical p::before {
    content: '';
    display: block;
    border-top: 0.2em dashed #ddd;
    /* 虚线边框样式 */
    margin-bottom: 2em;
    /* 与文本的距离 */
}




/* 响应式设计：适配小屏幕 */
@media (max-width: 768px) {
    .common-list {
        padding: 5vw;
        /* 在小屏幕上增加内边距 */
    }
}

@media (max-width: 480px) {
    .common-list {
        padding: 10vw;
        /* 在非常小的屏幕上进一步调整内边距 */
    }
}

.modal {
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    /* 黑色背景，半透明 */
    overflow-y: auto;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    max-width: 600px;
}

.close {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}
</style>